<template>
	<view>
		<view class="info">
			<view class="top-title">
				<view class="company">
					{{this.companyName}}
				</view>
			</view>
			<view class="wrapper" v-for="(item,index) in listData" :key="index" >
				<view class="title">
					{{item.position}}
					<view class="add-btn" @click="handleAddShow(item.position)">
						+ 添加人员
					</view>
				</view>
				<view class="value" v-for="(item2,index) in item.children" :key="index" >
					<view>
						<view class="member">
							<text class="name">
								{{item2.zrr_name}}
								<text @click="handleCall(item2.zrr_tel)" class="tel">
									<text class="iconfont icon-24gl-phoneLoudspeaker"></text>
									{{item2.zrr_tel}}
								</text>
							</text>
							<view class="evaluate">
								<view class="rate">
									{{item2.score}}分
								</view>
								<text class="iconfont icon-bianji1" @click="handleEditShow(item2)"></text>
								<text class="iconfont icon-shanchu" @click="delTipShow(item2.id)"></text>
							</view>
						</view>
						<view class="certificate">身份证：{{item2.zrr_identity}}</view>
					</view>
				</view>
			</view>
		</view>
		
		<u-modal :show="show" @confirm="confirmSubmit" @cancel="close" :content="modaltip" showCancelButton ref="uModal" ></u-modal>
		<u-popup mode="bottom" :show="showPop" @close="closePop" :round="10">
			<view class="section-pop">
				<view class="title">
					<text>{{ isAdd ? '添加': '编辑'}}责任人</text>
				</view>
				<view class="form-item">
					<view class="label">负责人</view>
					<view class="input">
						<u--input placeholderClass="input-placeholder" class="input-body"
							placeholder="请输入负责人" v-model="form.zrr_name"></u--input>
					</view>
				</view>
				<view class="form-item">
					<view class="label">电话</view>
					<view class="input">
						<u--input placeholderClass="input-placeholder" class="input-body"
							type="number" maxlength="11" placeholder="请输入电话" v-model="form.zrr_tel"></u--input>
					</view>
				</view>
				<view class="form-item">
					<view class="label">身份证</view>
					<view class="input">
						<u--input placeholderClass="input-placeholder" class="input-body"
							type="number" maxlength="18" placeholder="请输入身份证" v-model="form.zrr_identity"></u--input>
					</view>
				</view>
				<view class="form-item">
					<view class="label">职位</view>
					<view class="input">
						<input placeholderClass="input-placeholder" class="input-body" disabled="true"
							v-model="form.zrr_position"></input>
					</view>
				</view>
				<view class="custom-button" @click="submit(isAdd)">确认</view>
			</view>
		</u-popup>
		
	</view>
</template>

<script>
	import {
		companyListApi,
		addPersonApi,
		editPersonApi,
		delPersonApi,
		personListApi
	} from '@/api/person.js';
	export default {
		data() {
			return {
				isAdd: true,
				showPop: false,
				show: false,
				modaltip: '确认删除该人员吗',
				form: {
					link_id: '',
					zrr_position: '',
					zrr_name: '',
					zrr_tel: '',
					zrr_identity: '',
				},
				delId: '',
				editId: "",
				queryId: '',
				companyName: '',
				companyTd: '',
				listData: [],
			}
		},
		onLoad(op) {
			this.queryId = op.id;
			this.selectPerson();
		},
		methods: {
			async selectPerson() {
				let j = await personListApi({
					id: this.queryId
				})
				if (j.code = 1) {
					this.companyName = j.data.data.dw_name;
					this.companyTd = j.data.data.id;
					this.listData = j.data.data.list;
				}
			},
			delTipShow(id) {
				this.show = true;
				this.delId = id
			},
			async confirmSubmit() {
				let j = await delPersonApi({
					id: this.delId
				})
				if (j.code = 1) {
					this.showToast('删除成功');
					this.show = false;
					this.selectPerson();
				}
			},
			close() {
				this.show = false
			},
			async submit() {
				if(this.form.zrr_name != "" && this.form.zrr_tel != "" ){
					if(this.isAdd){
						let j = await addPersonApi({
							...this.form
						})
						if (j.code = 1) {
							this.showToast('添加成功')
							this.showPop = false;
							this.selectPerson();
						}
					}else{
						let j = await editPersonApi({
							...this.form,
							id: this.editId
						})
						if (j.code = 1) {
							this.showToast('修改成功')
							this.showPop = false;
							this.selectPerson();
						}
					}
				}else{
					uni.showToast({
						title: '请完善内容！',
						icon: 'none',
						duration: 1000
					})
				}
			},
			showToast(name) {
				uni.showToast({
					title: name,
					icon: 'none',
					duration: 1000
				})
			},
			showModal() {
				this.show = true;
			},
			handleAddShow(position) {
				// 清空表单信息
				this.form.zrr_name = "";
				this.form.zrr_tel = "";
				this.form.zrr_identity = "";
				
				this.showPop = true;
				this.isAdd = true;
				
				this.form.link_id = this.companyTd;
				this.form.zrr_position = position;
			},
			handleEditShow(info) {
				// 清空表单信息
				this.form.zrr_name = "";
				this.form.zrr_tel = "";
				this.form.zrr_identity = "";
				
				this.showPop = true;
				this.isAdd = false;
				
				this.editId = info.id
				this.form.zrr_name = info.zrr_name;
				this.form.zrr_tel = info.zrr_tel;
				this.form.zrr_identity = info.zrr_identity;
				this.form.zrr_position = info.zrr_position;
			},
			closePop() {
				this.showPop = false
			},
			handleCall(number) {
				uni.makePhoneCall({
				    phoneNumber: number
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.info{
		width: 100%;
		background-color: #fff;
		box-sizing: border-box;
		padding: 0 40rpx;
		margin-top: 30rpx;
		.top-title{
			width: 100%;
			margin-top: 12rpx;
			padding-bottom: 10rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.company{
				text-align: left;
				width: 600rpx;
				font-size: 26rpx;
				line-height: 25rpx;
				font-weight: bold;
				font-stretch: normal;
				letter-spacing: 2rpx;
				color: #3b3c40;	
				margin-right: 30rpx;
			}
			
		}
		.wrapper{
			width: 100%;
			border-radius: 35rpx;
			background-size: cover;
			background-repeat: no-repeat;
			overflow: hidden;
			box-sizing: border-box;
			box-shadow: 0 0 20rpx 10rpx rgba(#bcbcb5, 0.17);
			padding: 28rpx 40rpx;
			margin-top: 25rpx;
			margin-bottom: 24rpx;
			.title {
				width: 100%;
				height: 30rpx;
				line-height: 30rpx;
				border-bottom: solid 3rpx #f2f2f0;
				font-size: 26rpx;
				font-stretch: normal;
				letter-spacing: 0rpx;
				color: #3b3c40;
				padding-bottom: 28rpx;
				.add-btn{
					text-align: center;
					width: 189rpx;
					height: 40rpx;
					border-radius: 21rpx;
					border: solid 2rpx #1534ce;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					line-height: 40rpx;
					letter-spacing: 0rpx;
					color: #1534ce;
				}
				view {
					float: right;
					font-size: 26rpx;
					color: #8497ac;
					font-weight: normal;
					.iconfont{
						font-size: 26rpx;
						margin-right: 5rpx;
					}
				}
			}
		
			.value {
				width: 100%;
				padding-bottom: 10rpx;
				border-bottom: 1rpx solid #f2f2f0;
				.member{
					width: 100%;
					height: 40rpx;
					line-height: 40rpx;
					margin-bottom: 15rpx;
					margin-top: 15rpx;
					&:last-child{
						margin-bottom: 0;
					}
					.name{
						font-size: 26rpx;
						color: #3b3c40;
						margin-right: 10rpx;
						.tel{
							margin-left: 10rpx;
							color: #1d3bd0;
							.icon-24gl-phoneLoudspeaker{
								color: #1d3bd0;
								font-size: 26rpx;
								margin-right: 5rpx;
							}
						}
					}
					.evaluate{
						float: right;
						.rate{
							display: inline-block;
							margin-right: 20rpx;
							font-size: 26rpx;
						}
						.evaluate-btn{
							width: 150rpx;
							font-size: 24rpx;
							padding: 2rpx 15rpx;
							border-radius: 20rpx;
							border: 1px solid #1d3bd0;
							color: #1d3bd0;
							font-weight: bold;
						}
					}
					.icon-bianji1{
						color: #1d3bd0;
						font-size: 28rpx;
						margin-right: 10rpx;
					}
					.icon-shanchu{
						color: red;
						font-size: 28rpx;
					}
				}
				.certificate{
					font-size: 26rpx;
				}
			}
			
		}
	}
	
	.section-pop {
		width: 100%;
		border-radius: 50rpx;
		padding-top: 20rpx;
		padding-bottom: 50rpx;
		.title{
			padding-left: 20rpx;
			padding-bottom: 40rpx;
			font-weight: bold;
		}
	}
	.form-item {
		width: 750rpx;
		line-height: 48rpx;
		margin: 0 auto;
		margin-bottom: 25rpx;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		padding: 0 40rpx;
		&:last-child {
			margin-bottom: 34rpx;
		}
	
		&.upload-wrap {
			align-items: unset;
			height: unset;
			line-height: unset;
		}
	
		@include clear();
	
		.label {
			float: left;
			width: 120rpx;
			height: 48rpx;
			text-align: left;
			line-height: 44rpx;
			font-size: 26rpx;
			color: #46464a;
		}
		.input {
			float: left;
			width: calc(100% - 134rpx - 3rpx - 30rpx);
			border-radius: 20rpx;
			border: solid 2rpx #1534ce;
			.input-body {
				box-sizing: border-box;
				width: 100%;
				height: 44rpx;
				padding: 0 !important;
				border: none;
				padding-left: 30rpx !important;
				padding-right: 30rpx !important;
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				letter-spacing: 0rpx;
				color: rgba(0, 0, 0, 0.8);
				line-height: 44rpx;
				/deep/ .uni-input-input{
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: rgba(0, 0, 0, 0.8);
				}
				
			}
			
			.input-placeholder {
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				letter-spacing: 0rpx;
				color: rgba(0, 0, 0, 0.5);
			}
		}
	
	}
</style>
